<template>
  <V-CommonHeaderLeft>
    <div class="purchasing-order">
      <Navigation :msg="navMsg"></Navigation>
      <div class="purchasing-table">
        <el-table ref="multipleTable"
                  :data="stock"
                  style="width: 100%;"
                  :height="tableHeight"
                  class="table-class">
          <el-table-column type='index'
                           min-width='5%'
                           label="序号">
          </el-table-column>
          <el-table-column min-width='10%'
                           label="单号"
                           sortable>
            <template slot-scope="scope">
              <span :title="scope.row.orderId">{{ scope.row.orderId }}</span>
            </template>
          </el-table-column>
          <el-table-column min-width='10%'
                           label="付款方">
            <template slot-scope="scope">
              <span class="payer">
                <span v-if="scope.row.from.type == '客户'"
                      style="color:#65D142;">[客]</span>
                <span v-else
                      style="color:#20ade5;">[供]</span>
                {{ scope.row.from.name }}
              </span>
            </template>
          </el-table-column>
          <el-table-column min-width='10%'
                           label="收款金额"
                           sortable>
            <template slot-scope="scope">
              <span :title="scope.row.orderId">{{ scope.row.orderId }}</span>
            </template>
          </el-table-column>
          <el-table-column min-width='8.56%'
                           label="收入类别">
            <template slot-scope="scope">
              <span :title="scope.row.orderId">{{ scope.row.orderId }}</span>
            </template>
          </el-table-column>
          <el-table-column min-width='8.56%'
                           label="收款账户">
            <template slot-scope="scope">
              <span :title="scope.row.orderId">{{ scope.row.orderId }}</span>
            </template>
          </el-table-column>
          <el-table-column min-width='8%'
                           label="单据状态">
            <template slot-scope="scope">
              <span :style="scope.row.orderStatus == '已完成' ? '' : 'color: #ff3838;'">{{ scope.row.orderStatus }}</span>
            </template>
          </el-table-column>
          <el-table-column min-width='8.56%'
                           label="制单人">
            <template slot-scope="scope">
              <span :title="scope.row.orderPerson">{{ scope.row.orderPerson }}</span>
            </template>
          </el-table-column>
          <el-table-column min-width='8.56%'
                           label="审核人">
            <template slot-scope="scope">
              <span :title="scope.row.orderPerson">{{ scope.row.orderPerson }}</span>
            </template>
          </el-table-column>
          <el-table-column min-width='8.56%'
                           label="收款时间">
            <template slot-scope="scope">
              <span :title="scope.row.auditTime">{{ scope.row.auditTime }}</span>
            </template>
          </el-table-column>
          <el-table-column min-width='8.56%'
                           sortable
                           label="提交时间">
            <template slot-scope="scope">
              <span :title="scope.row.submitTime">{{ scope.row.submitTime }}</span>
              <div class="hover-box">
                <router-link v-if="scope.row.orderStatus == '待审核'"
                             to="#">审核</router-link>
              </div>
            </template>
          </el-table-column>
        </el-table>
        <Paging :msg="pageMsg.length"
                ref="fn"
                @pageNum="getPageNum"
                @pageId="getPageId"></Paging>
      </div>
    </div>
  </V-CommonHeaderLeft>
</template>
<script>
import VCommonHeaderLeft from '@/components/common/vCommonHeaderLeft/VCommonHeaderLeft'
import Navigation from '@/components/common/navigation/Navigation'
import Paging from '@/components/common/paging/Paging'
export default {
  data () {
    return {
      tableHeight: '',
      pageNum: 15, // 每页默认显示15条,
      pageId: 1, // 页面id
      judgeStatus: false, // 排序状态
      navMsg: [
        {
          name: '财务',
          path: '/receipt'
        },
        {
          name: '收款单',
          path: ''
        }
      ],
      stock: [],
      pageMsg: [
        {
          id: 1,
          orderId: 'CK-20190412-0003',
          from: {
            type: '客户',
            name: '深圳宝能太古'
          },
          outType: '销售出库',
          outWarehouse: '深圳仓',
          orderStatus: '已完成',
          outEstimated: '2019-04-22',
          orderPerson: '陈素然',
          auditTime: '2019-04-22',
          submitTime: '2019-04-22',
          eemarks: ''
        },
        {
          orderId: 'CK-20200422-0563',
          from: {
            type: '供',
            name: '深圳宝能太古'
          },
          outType: '销售出库',
          outWarehouse: '深圳仓',
          orderStatus: '待审核',
          outEstimated: '2019-04-22',
          orderPerson: '陈素然',
          auditTime: '2019-04-21',
          submitTime: '2019-04-23',
          eemarks: ''
        }
      ]
    }
  },
  components: {
    Navigation,
    Paging,
    VCommonHeaderLeft
  },
  created () {
    this.stock = this.pageMsg
    this.getHight()
    window.addEventListener('resize', this.getHight)
  },
  destroyed () {
    window.removeEventListener('resize', this.getHight)
  },
  methods: {
    getHight () {
      this.tableHeight = window.innerHeight - 162 + 'px'
    },
    getPageId (id = 1) {
      this.pageId = id
      this.stock = this.$refs.fn.sliceArray(this.pageMsg, this.pageNum, id - 1)
    },
    getPageNum (num) {
      this.pageNum = num
      this.getPageId()
    }
  }
}
</script>
<style lang="scss" scoped>
.purchasing-order {
  width: 100%;
  height: calc(100vh - 60px);
  margin-right: 10px;
  overflow: hidden;
  background-color: #ffffff;
  .purchasing-table {
    width: 100%;
    overflow: hidden;
    @mixin el-common($el-color, $el-height, $el-class) {
      padding: 0;
      color: $el-color;
      height: $el-height;
      line-height: $el-height;
      &:first-child {
        text-align: center;
      }
      #{$el-class} {
        width: 100%;
        line-height: 20px;
        display: -webkit-box;
        overflow: hidden;
        white-space: normal !important;
        text-overflow: ellipsis;
        word-wrap: break-word;
        word-break: break-all;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
      }
    }
    /deep/ .el-table__body-wrapper {
      overflow-x: hidden;
      overflow-y: hidden;
      &:hover {
        overflow-y: overlay;
      }
      &::-webkit-scrollbar {
        width: 8px;
        height: 50%;
      }
      &::-webkit-scrollbar-thumb {
        border-radius: 10px;
        background-color: rgba(0, 0, 0, 0.2);
      }
      &::-webkit-scrollbar-track {
        border-radius: 0;
        background-color: rgba(0, 0, 0, 0.1);
      }
    }
    /deep/ .table-class {
      font-size: 12px;
      tr {
        position: relative;
        &:hover {
          .hover-box {
            display: flex;
          }
        }
        td {
          @include el-common(
            $el-color: #333,
            $el-height: 40px,
            $el-class: "span"
          );
          .payer {
            span {
              padding: 0;
              &:first-child {
                display: inline;
                padding-right: 4px;
              }
            }
          }
          .hover-box {
            display: none;
            position: absolute;
            top: 0;
            right: 0;
            height: 100%;
            border: 0 none;
            background-color: #a3bbd4;
            box-shadow: none;
            align-items: center;
            text-align: center;
            cursor: pointer;
            white-space: normal;
            word-break: normal;
            z-index: 2;
            a {
              display: flex;
              width: 80px;
              color: #ffffff;
              height: 100%;
              justify-content: center;
              align-items: center;
              font-size: 12px;
            }
          }
        }
        th {
          @include el-common(
            $el-color: #666,
            $el-height: 50px,
            $el-class: ".cell"
          );
          font-weight: normal;
          background-color: #fcfcfc;
        }
      }
      &::before {
        display: none;
      }
    }
  }
}
</style>
